import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
//1.将组件加入组件堆
import Login from "@/components/Login.vue";
import Home from "@/components/Home.vue";
import Welcome from "@/components/0Welcome/welcome.vue";
import BaseData from "@/components/1BaseData/BaseData.vue";
import Evaluate from "@/components/2Evaluate/Evaluate.vue";
import PrettyGood from "@/components/3PrettyGood/PrettyGood.vue";
import PrettyGood2 from "@/components/3PrettyGood/PrettyGood2.vue";
import PrettyGood3 from "@/components/3PrettyGood/PrettyGood3.vue";
import OnlineServiceGraph from "@/components/4OnlineService/OnlineServiceGraph.vue";
import NotAccomplish from "@/components/5NotAccomplish/NotAccomplish.vue";
import NotAccomplish2 from "@/components/5NotAccomplish/NotAccomplish2.vue";
import ServiceTimes from "@/components/6ServiceTimes/ServiceTimes.vue";
import ServiceTimes2 from "@/components/6ServiceTimes/ServiceTimes2.vue";
import ServiceTimes3 from "@/components/6ServiceTimes/ServiceTimes3.vue";
import TimeAnalyse from "@/components/7TimeAnalyse/TimeAnalyse.vue";
import UpLoadDoc from "@/components/8DocCreate/UpLoad.vue";
import UpLoadDoc2 from "@/components/8DocCreate/UpLoad2.vue";
import WebService from "@/components/9WebService/webService.vue";
import oldUpload from "@/components/10DataCompare/oldUpload.vue";

import PrettyGood1A from '@/components/3PrettyGood/PrettyGood1A.vue';
import PrettyGood1B from '@/components/3PrettyGood/PrettyGood1B.vue';

//2.在路由规则数组中新增一个路由规则
const routes = [

  {
    //定义路由的url名称
    path: '/login',
    //定义路由页面所在位置
    component: Login
  },
  {
    path: '/home',
    component: Home,
    //进入home组件之后会重定向到默认的路由规则里
    redirect: '/welcome',
    // 在这里写home路由下的子路由规则
    children: [
      { path: '/welcome' , component: Welcome },
      { path: '/baseData' , component: BaseData},
      { path: '/evaluate' , component: Evaluate},
      { path: '/prettyGood' , component: PrettyGood},
      { path: '/prettyGood2' , component: PrettyGood2},
      { path: '/prettyGood3' , component: PrettyGood3},
      { path: '/onlineServiceGraph' , component: OnlineServiceGraph},
      { path: '/notAccomplish' , component: NotAccomplish},
      { path: '/notAccomplish2' , component: NotAccomplish2},
      { path: '/serviceTimes' , component: ServiceTimes},
      { path: '/serviceTimes2' , component: ServiceTimes2},
      { path: '/serviceTimes3' , component: ServiceTimes3},
      { path: '/timeAnalyse' , component: TimeAnalyse},
      { path: '/docCreate' , component: UpLoadDoc},
      { path: '/docCreate2' , component: UpLoadDoc2},
      { path: '/webService' , component: WebService},
      { path: '/oldUpload' , component: oldUpload},

      { path: '/prettyGood1A' , name: 'prettyGood1A' , component: PrettyGood1A},
      { path: '/prettyGood1B' , name: 'prettyGood1B' , component: PrettyGood1B},
    ]
  },
  {
    //路由重定向————源路由
    path: '/' ,
    //路由重定向————目标路由
    redirect: '/login'
  },

]
  //3.以上动作完成之后可以用路由占位符使用这些路由规则(在App.vue的<div>里)
  //<router-view> </router-view>
/*
* 路由占位符的特点：
*   1.路由占位符的位置会出现索引过去的页面
*   2.只有在路由通过对应的url索引过去的时候才能显示
*   3.可以设定根路径，让路由自动重定向到某个地址
*
* */
const router = new VueRouter({
  // 去除vue访问页面上的#
  mode: 'history',
  // mode: 'hash',
  // base: process.env.BASE_URL,
  base: '/niaoqing/',
  routes
})

// 挂载一个默认的路由导航守卫
/*router.beforeEach((to , from , next) => {
  // to代表要访问的路径
  // from代表从哪个路径跳转而来
  // next是一个函数，表示放行
  //     用法: 1.next()   放行
  //          2.next('/login') 强制跳转
  /!*
  * 登录页不需要做权限控制（需要注意注册页和忘记密码页）
  * 有token就让其登录，没有token就拦截
  * *!/
  if(to.path === '/login') return next()
  else {
    //获取token
    const id = window.sessionStorage.getItem('username')
    //没有token就拦截
    if (!id) return next('/login')
    //有token就登录
    else next()
  }
})*/


export default router
